package com.aispeech.astools.view;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.aispeech.astools.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class MainActivity extends Activity implements OnItemClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ListView listView = findViewById(R.id.lv_items);
        ArrayList<HashMap<String, Object>> listItems = new ArrayList<>();

        HashMap<String, Object> item;

        item = new HashMap<>();
        item.put("activity_name", "系统信息");
        item.put("activity_class", SystemInfoActivity.class);
        listItems.add(item);

        item = new HashMap<>();
        item.put("activity_name", "接口测试");
        item.put("activity_class", SysIntTestActivity.class);
        listItems.add(item);

        item = new HashMap<>();
        item.put("activity_name", "AudioRecord录音测试");
        item.put("activity_class", RecordActivity.class);
        listItems.add(item);

        item = new HashMap<>();
        item.put("activity_name", "Jni Record录音测试");
        item.put("activity_class", AIJniRecordTestActivity.class);
        listItems.add(item);

        item = new HashMap<>();
        item.put("activity_name", "遥控器录音测试");
        item.put("activity_class", RemoteRecordActivity.class);
        listItems.add(item);

        item = new HashMap<>();
        item.put("activity_name", "串口测试");
        item.put("activity_class", SerialActivity.class);
        listItems.add(item);

        item = new HashMap<>();
        item.put("activity_name", "3308串口测试");
        item.put("activity_class", Serial3308Activity.class);
        listItems.add(item);

        SimpleAdapter adapter = new SimpleAdapter(this, listItems, R.layout.list_item,
                new String[]{"activity_name"}, new int[]{R.id.tv_act_item});

        listView.setAdapter(adapter);
        listView.setDividerHeight(2);

        listView.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Map<?, ?> map = (HashMap<?, ?>) parent.getAdapter().getItem(position);
        Class<?> clazz = (Class<?>) map.get("activity_class");
        Intent it = new Intent(this, clazz);
        this.startActivity(it);
    }
}
